<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class CompanyGauges extends Page
{
       public $Image3 = null;
       public $cmbGaugeHours = null;
       public $cmbGaugeDays = null;
       public $cmbGaugeMiles = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $chkShowOrder = null;
       public $JTGroupReminders = null;
       public $lblSchedulingHours = null;
       public $edSchedulingHours = null;
       public $lblSchedulingMiles = null;
       public $edSchedulingMiles = null;
       public $JTGroupScheduling = null;
       public $edAdvanceHours = null;
       public $edAdvanceDays = null;
       public $edAdvanceMiles = null;
       public $lblAdvanceHours = null;
       public $lblAdvanceDays = null;
       public $lblAdvanceMiles = null;
       public $JTGroupAdvance = null;
       public $lblGaugesHours = null;
       public $lblGaugesDays = null;
       public $lblGaugesMiles = null;
       public $JTGroupGauge = null;
       public $JTSiteTheme1 = null;

       function btnSubmitClick($sender, $params)
       {

       if ($this->chkShowOrder->Checked==true)
       {
       $chkShowOrder ='1';
       }
       else
       {
       $chkShowOrder='0';
       }


       $result=mysql_query("select * from company_gauges_tbl where company_id='".$_SESSION['company_id']."'");
       $count=mysql_num_rows($result);
       if($count==0)
       {
       mysql_query("insert into company_gauges_tbl (company_id,
       gauge_miles,
       gauge_days,
       gauge_hours,
       advance_miles,
       advance_days,
       advance_hours,
       scheduling_miles,
       scheduling_hours,
       show_order)

       Values('".$_SESSION['company_id']."',
       '".$this->cmbGaugeMiles->getItemIndex()."',
       '".$this->cmbGaugeDays->getItemIndex()."',
       '".$this->cmbGaugeHours->getItemIndex()."',
       '".$this->edAdvanceMiles->Text."',
       '".$this->edAdvanceDays->Text."',
       '".$this->edAdvanceHours->Text."',
       '".$this->edSchedulingMiles->Text."',
       '".$this->edSchedulingHours->Text."',
       '".$chkShowOrder."')") or die ("insert gauges - " . mysql_error());
       }
       else
       {
       mysql_query("update company_gauges_tbl set
       gauge_miles='".$this->cmbGaugeMiles->getItemIndex()."',
       gauge_days='".$this->cmbGaugeDays->getItemIndex()."',
       gauge_hours='".$this->cmbGaugeHours->getItemIndex()."',
       advance_miles='".$this->edAdvanceMiles->Text."',
       advance_days='".$this->edAdvanceDays->Text."',
       advance_hours='".$this->edAdvanceHours->Text."',
       scheduling_miles='".$this->edSchedulingMiles->Text."',
       scheduling_hours='".$this->edSchedulingHours->Text."',
       show_order='".$chkShowOrder."'
       where company_id='".$_SESSION['company_id']."'") or die ("update gauges - " . mysql_error());
       }
       redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);

       }


       function btnCancelClick($sender, $params)
       {
        redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);
       }


       function CompanyGaugesCreate($sender, $params)
       {

       $query = "select * from company_gauges_tbl where company_id= '".$_SESSION['company_id']."'";
       $result_show = mysql_query($query)or die("SELECT GAUGES - " . mysql_error());
       $row= mysql_fetch_array($result_show);

      if($row['show_order']=='1')
      {
      $this->chkShowOrder->Checked=true;
      }
      else
      {
      $this->chkShowOrder->Checked=false;
      }
       $this->cmbGaugeMiles->ItemIndex = $row['gauge_miles'];
       $this->cmbGaugeHours->ItemIndex = $row['gauge_hours'];
       $this->cmbGaugeDays->ItemIndex = $row['gauge_days'];
       $this->edAdvanceMiles->Text = $row['advance_miles'];
       $this->edAdvanceDays->Text = $row['advance_days'];
       $this->edAdvanceHours->Text = $row['advance_hours'];
       $this->edSchedulingMiles->Text = $row['scheduling_miles'];
       $this->edSchedulingHours->Text = $row['scheduling_hours'];

       $result_unit = mysql_query("select * from company_measures_tbl where company_id='".$_SESSION['company_id']."'");
       $row_unit = mysql_fetch_array($result_unit);
       $label_unit = $row_unit['system_measure'];

       if($label_unit=='Metric Measurement (km, Liters, L100 km)')
       {
        $this->lblGaugesMiles->Caption = 'km';
        $this->lblAdvanceMiles->Caption = 'km';
        $this->lblSchedulingMiles->Caption = 'km';
       }
       else
       {
        $this->lblGaugesMiles->Caption = 'Miles';
        $this->lblAdvanceMiles->Caption = 'Miles';
        $this->lblSchedulingMiles->Caption = 'Miles';
       }


       }

}

global $application;

global $CompanyGauges;

//Creates the form
$CompanyGauges=new CompanyGauges($application);

//Read from resource file
$CompanyGauges->loadResource(__FILE__);

//Shows the form
$CompanyGauges->show();

?>